using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;

namespace TestImport
{
    
    public class DB_Connection
    {
        private string ConnectionString = "";
        private SqlConnection Connection;
        private SqlCommand sql_query;
        private Boolean connected = false;

        public SqlDataReader Resultset;


        public DB_Connection(String ConnectionString)
        {
            this.ConnectionString = ConnectionString;
        }

        public void Connect()
        {
            try
            {
                this.Connection = new SqlConnection(this.ConnectionString);
                this.Connection.Open();
                this.connected = true;

            }
            catch
            {
                //throw new IsosException("Could not connect to database");
            }
        }

        public void query(string query)
        {
            if (!this.connected)
                Connect();

            if (Resultset is SqlDataReader)
                this.Resultset.Close();
            this.sql_query = new SqlCommand(query, this.Connection);

            if (query.Split(" "[0])[0].Equals("SELECT"))
                this.Resultset = this.sql_query.ExecuteReader();
            else
                this.sql_query.ExecuteNonQuery();
 
        }

        public void Close()
        {
            if (this.connected)
            {
                this.Connection.Close();
            }
        }
    }


    public class db_check
    {
        public db_check(){}



    }
}



